﻿using IntelligentAgriculture.Contracts.Interface;
using IntelligentAgriculture.Domain.Entity;
using IntelligentAgriculture.WebAPI.Application.Command.BreedingWeighCommand;
using MediatR;

namespace IntelligentAgriculture.WebAPI.Application.CommandHandler.BreedingWeighCommandHandler
{
    public class BreedingUpdateCommandHandler : IRequestHandler<BreedingWeighUpdateCommand, Results<int>>
    {


        private readonly IBreedingWeighService breeingService;
        private readonly ILogger<BreedingUpdateCommandHandler> logger;
        public BreedingUpdateCommandHandler(IBreedingWeighService breeingService, ILogger<BreedingUpdateCommandHandler> logger)
        {
            this.breeingService = breeingService;
            this.logger = logger;
        }


        public async Task<Results<int>> Handle(BreedingWeighUpdateCommand request, CancellationToken cancellationToken)
        {
            var result = new Breedingweigh()
            {
                BreedingId = request.BreedingId,
                WeighDate = DateTime.Now,
                EarTag = request.EarTag,
                Weight = request.Weight,
                WeighCategory = request.WeighCategory,
            };

            var list = await breeingService.Update(result);

            return Results<int>.DataResult(list);

        }





    }





}
